$(document).ready(function () {
 
  	zig.embed();
  	console.log("Browser plugin installed: " + zig.pluginInstalled);
	console.log("Browser plugin version: " + zig.pluginVersion);
	console.log("Zig.js version: " + zig.version);
	zig.addEventListener('statuschange', function() {
		console.log("Sensor connected: " + zig.sensorConnected);
	});
	// Method 1: specific event listeners
zig.addEventListener('userfound', function(user) {
	console.log('Found user. ID: ' + user.id);
});
zig.addEventListener('userlost', function(user) {
	console.log('Lost user. ID: ' + user.id);
});

var engager = zig.EngageUsersWithSkeleton(1);
engager.addEventListener('userengaged', function(user) {
	console.log('User engaged: ' + user.id);
});
engager.addEventListener('userdisengaged', function(user) {
	console.log('User disengaged: ' + user.id);
});
zig.addListener(engager);
	

zig.singleUserSession.addEventListener('userengaged', function(user) {
	console.log('User started UI session: ' + user.id);
});
zig.singleUserSession.addEventListener('userdisengaged', function(user) {
	console.log('User ended UI session: ' + user.id);
});
zig.singleUserSession.addEventListener('sessionstart', function(initialPosition) {
	console.log('Session started at ' + initialPosition);
});
zig.singleUserSession.addEventListener('sessionend', function() {
	console.log('Session ended')
});

/*---------------------------------------*/

/* var f = zig.controls.Fader(zig.Orientation.Y);
f.itemsCount = 4;
f.addEventListener('hoverstart', function (f) {
	$("#2").trigger('hover');
	console.log('Fader item hover: ' + f.hoverItem);
});
f.addEventListener('hoverstop', function(f) {
	console.log('Fader item not hovering any more: ' + f.hoverItem);
})
zig.singleUserSession.addListener(f);
*/
// PushDetector
var pushDetector = zig.controls.PushDetector();
pushDetector.addEventListener('push', function(pd) {
	console.log('PushDetector: Push');
});
pushDetector.addEventListener('release', function(pd) {
	console.log('PushDetector: Release');
});
pushDetector.addEventListener('click', function(pd) {
	console.log('PushDetector: Click');
});
zig.singleUserSession.addListener(pushDetector);

// SwipeDetector
var swipeDetector = zig.controls.SwipeDetector();

swipeDetector.addEventListener('swipeleft', function(pd) {
	console.log('SwipeDetector: Swipe Left');
	var current= $('.activeSlide').attr('id');
	console.log(current);
	
});
swipeDetector.addEventListener('swiperight', function(pd) {
	console.log('SwipeDetector: Swipe Right');
});
swipeDetector.addEventListener('swipe', function(dir) {
	console.log('SwipeDetector: Swipe direction: ' + dir);
});
zig.singleUserSession.addListener(swipeDetector);

// WaveDetector
var waveDetector = zig.controls.WaveDetector();
waveDetector.addEventListener('wave', function(pd) {
	console.log('WaveDetector: Wave');
});
zig.singleUserSession.addListener(waveDetector);


function usersRadar(parentElement) {
	// physical dimensions of radar in room. Lets use 4m x 4m
	this.radarWidth = 4000;
	this.radarHeight = 4000;
 
	this.onuserfound = function(user) {
		// create a new element for this user, add to dom
		var el = document.createElement('div');
		el.classList.add('user');
		parentElement.appendChild(el);
		// we can simply add the newly created element to the tracked user object
		// for later
		user.radarElement = el;
 
		// move the element every frame
		var that = this;
		user.addEventListener('userupdate', function(user) {
			// we need to convert [user.x, user.z] to [screen.x, screen.y]
			// first get normalized user position
			var xpos = (user.position[0] / that.radarWidth) + 0.5; // 0 for x is actually the center of the depthmap
			var ypos = (user.position[2] / that.radarHeight);
			// convert normalized position to fit into our radar element
			var el = user.radarElement;
			el.style.left = xpos * parentElement.offsetWidth - (el.offsetWidth / 2) + "px";
			el.style.top = ypos * parentElement.offsetHeight - (el.offsetHeight / 2) + "px";
		});
	}
	
	this.onuserlost = function(user) {
		// remove the element we created from the dom and ZDK user object
		parentElement.removeChild(user.radarElement);
		delete user.radarElement;
	}
}
 
// make sure you add <div id='radar'></div> to your html body
var radar = new usersRadar(document.getElementById('radar'));
zig.addListener(radar);




















});